Page({
  data: {
    // 玩家数据
    playerData: {
      userName: '小丸子',
      level: 19,
      coins: 1000
    },
    
    // 关卡数据 - 按类别分组
    levelList: [
      // 生活服务类
      {
        id: 1,
        name: '房屋办理',
        description: '学习房产证、过户等手续办理流程',
        icon: '🏠',
        category: '生活服务',
        difficulty: '简单',
        reward: 100,
        status: 'unlocked', // unlocked, in-progress, completed, locked
        progress: 0,
        statusText: '开始'
      },
      {
        id: 2,
        name: '子女入学',
        description: '掌握幼儿园到小学的入学申请流程',
        icon: '📚',
        category: '生活服务',
        difficulty: '中等',
        reward: 150,
        status: 'in-progress',
        progress: 65,
        statusText: '继续'
      },
      {
        id: 3,
        name: '医疗指南',
        description: '熟悉医院挂号、看病、报销等流程',
        icon: '🏥',
        category: '生活服务',
        difficulty: '中等',
        reward: 180,
        status: 'unlocked',
        progress: 0,
        statusText: '开始'
      },
      
      // 文化地标类
      {
        id: 4,
        name: '鸡鸣阁',
        description: '探索古建筑的历史文化和经营管理',
        icon: '🏰',
        category: '文化地标',
        difficulty: '困难',
        reward: 250,
        status: 'locked',
        progress: 0,
        statusText: '待解锁'
      },
      {
        id: 5,
        name: '商贸城',
        description: '体验现代商业综合体的运营模式',
        icon: '🏪',
        category: '文化地标',
        difficulty: '中等',
        reward: 200,
        status: 'completed',
        progress: 100,
        statusText: '已通关'
      },
      {
        id: 6,
        name: '佛堂古镇',
        description: '了解古镇文化保护和旅游开发',
        icon: '🏯',
        category: '文化地标',
        difficulty: '简单',
        reward: 120,
        status: 'unlocked',
        progress: 0,
        statusText: '开始'
      },
      
      // 商贸实践类
      {
        id: 7,
        name: '采购模拟',
        description: '学习企业采购流程和成本控制',
        icon: '📊',
        category: '商贸实践',
        difficulty: '中等',
        reward: 180,
        status: 'locked',
        progress: 0,
        statusText: '待解锁'
      },
      {
        id: 8,
        name: '合同签订',
        description: '掌握商务合同起草和签订要点',
        icon: '📄',
        category: '商贸实践',
        difficulty: '困难',
        reward: 300,
        status: 'locked',
        progress: 0,
        statusText: '待解锁'
      }
    ]
  },

  onLoad() {
    console.log('关卡选择页面加载');
  },

  // 顶部状态栏组件事件处理
  onAvatarTap() {
    wx.showToast({
      title: '点击了头像',
      icon: 'none'
    });
  },

  onCoinTap() {
    wx.showModal({
      title: '金币信息',
      content: `当前金币: ${this.data.playerData.coins}`,
      showCancel: false
    });
  },

  onLevelTap() {
    wx.showToast({
      title: `当前等级: LV.${this.data.playerData.level}`,
      icon: 'none'
    });
  },

  // 关卡点击事件
  onLevelItemTap(e) {
    const levelId = e.currentTarget.dataset.id;
    const level = this.data.levelList.find(item => item.id === levelId);
    
    if (level.status === 'locked') {
      wx.showToast({
        title: '该关卡尚未解锁',
        icon: 'none'
      });
      return;
    }

    if (level.status === 'completed') {
      wx.showModal({
        title: '关卡已完成',
        content: `您已完成「${level.name}」关卡，是否要重新挑战？`,
        success: (res) => {
          if (res.confirm) {
            this.enterLevel(level);
          }
        }
      });
    } else {
      this.enterLevel(level);
    }
  },

  // 进入关卡
  enterLevel(level) {
    wx.showLoading({
      title: '正在进入关卡...'
    });

    setTimeout(() => {
      wx.hideLoading();
      wx.navigateTo({
        url: `/pages/levelDetail/index?id=${level.id}&name=${level.name}`,
        fail: () => {
          wx.showToast({
            title: '关卡详情页开发中',
            icon: 'none'
          });
        }
      });
    }, 1000);
  },

  // 返回首页
  onBackHome() {
    wx.navigateBack();
  }
});